package com.wing.system.controller.admin;

import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.system.service.DingTalkAttendanceGroupService;
import com.wing.system.service.DingTalkAttendanceService;
import com.wing.user.feign.UserClient;
import com.wing.user.model.request.SystemDingTalkInfo;
import com.wing.user.model.request.SystemDingTalkInfoForm;
import com.wing.web.annotation.RequestObjectFieldIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author
 */
@Validated
@Api(value = "Admin-钉钉同步管理", tags = "#/system/systemSyncDingTalkInfo")
@RestController("SystemDingTalkJobController")
@RequestMapping("system/admin/systemSyncDingTalkInfo")
@RequiredArgsConstructor
public class SystemDingTalkJobController {


    @Autowired
    UserClient userClient;

    @Autowired
    DingTalkAttendanceService dingTalkAttendanceService;

    @Autowired
    DingTalkAttendanceGroupService dingTalkAttendanceGroupService;

    @ApiOperation(value = "同步钉钉部门信息到本地系统", notes = "同步")
    @PostMapping("/syncDingDeptToSysRole")
/*    @Scheduled(cron = "0 0/5 * * * ?") // 每5分钟执行一次*/
    //@Scheduled(cron = "*/30 * * * * ?")
    public void syncDingDeptToSysRole() {
          userClient.syncDingDeptToSysRole();
    }



    @ApiOperation(value = "同步钉钉用户信息到本地系统", notes = "同步")
    @PostMapping("/syncDingUserToSysUer")
    //@Scheduled(cron = "*/30 * * * * ?")
    public void syncDingUserToSysUer() {
        userClient.syncDingUserToSysUer();
    }


    @ApiOperation(value = "定时任务同步钉钉考勤相关数据", notes = "添加")
    @RequestObjectFieldIgnore({"id", "createTime", "remark"})
    @GetMapping("/syncDingAttendanceToSystem")
    public void syncDingAttendanceToSystem(@RequestParam(name = "beginTime") String beginTime,@RequestParam(name = "endTime") String endTime) throws Exception {
        dingTalkAttendanceService.syncDingAttendanceToSystem(beginTime,endTime);
    }


    @ApiOperation(value = "手动同步钉钉考勤班次相关数据", notes = "同步")
    @PostMapping("/syncDingAttendanceBanCiSystem")
    //@Scheduled(cron = "*/30 * * * * ?")
    public void syncDingAttendanceBanCiSystem() throws Exception {
        dingTalkAttendanceService.syncDingAttendanceBanCiSystem();
    }



    @ApiOperation(value = "手动同步钉钉考勤组相关数据", notes = "添加")
    @GetMapping("/syncDingAttendanceGroupToSystem")
    public void syncDingAttendanceGroupToSystem() throws Exception {
        dingTalkAttendanceGroupService.syncDingAttendanceGroupToSystem();
    }

}
